package com.looookme.shaozhuo.uicompent;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.Toast;

import com.looookme.shaozhuo.mb_study.R;


/**
 * Created by Shaozhuo on 2015/9/8.
 */
public class Ui_ProgressBar extends Activity {
    private int _max = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.uiuppperlayout_progress);

        initData();
    }

    private final int MSG_WAHTING = 1;
    private final int MSG_WHATED = 2;
    private Handler mHanlder = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                case MSG_WAHTING:
                    modifyView();
                    break;
                case MSG_WHATED:
                    Toast.makeText(Ui_ProgressBar.this, "ProgressBar 耗时完成", Toast.LENGTH_SHORT).show();
                    break;
            }
        }
    };

    private void modifyView() {
        ((android.widget.ProgressBar)findViewById(R.id.uiupper_progress1)).setProgress(_max);
        ((android.widget.ProgressBar)findViewById(R.id.uiupper_progress2)).setProgress(_max);
        ((android.widget.ProgressBar)findViewById(R.id.uiupper_progress3)).setProgress(_max);
        ((android.widget.ProgressBar)findViewById(R.id.uiupper_progress4)).setProgress(_max);
        ((android.widget.ProgressBar)findViewById(R.id.uiupper_progress5)).setProgress(_max);
        ((android.widget.ProgressBar)findViewById(R.id.uiupper_progress6)).setProgress(_max);
    }

    private void initData() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                while(true){
                    _max += Math.random() * 10;
                    Log.i("TTTTTTTTTT", _max + "");
                    try {
                        Thread.sleep(200);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                    if(_max <= 100){
                        mHanlder.sendEmptyMessage(MSG_WAHTING);
                    }else{
                        mHanlder.sendEmptyMessage(MSG_WHATED);
                        break;
                    }
                }

            }
        }).start();
    }
}
